package week120;

import java.util.Arrays;

public class Solution {
    public int[] sortedSquares(int[] A) {
        int[] ans = new int[A.length];
        for (int i = 0; i < A.length; i++) {
            ans[i] = A[i] * A[i];
        }
        Arrays.sort(ans);
        return ans;
    }

    public int maxTurbulenceSize(int[] A) {
        int max = 1;
        if (A.length > 1) {
            int len = 2;
            max = 2;
            for (int i = 2; i < A.length; i++) {
                if ((A[i] > A[i - 1] && A[i - 1] < A[i - 2]) || (A[i] < A[i - 1] && A[i - 1] > A[i - 2])) {
                    len++;
                    max = Math.max(len, max);
                } else {
                    len = 2;
                }
            }
        }
        return max;
    }

    public static void main(String[] args) {
        Solution solution = new Solution();
        System.out.println(solution.maxTurbulenceSize(new int[]{9, 4, 2, 10, 7, 8, 8, 1, 9}));
        System.out.println(solution.maxTurbulenceSize(new int[]{4, 8, 12, 16}));
        System.out.println(solution.maxTurbulenceSize(new int[]{100}));
        System.out.println(solution.maxTurbulenceSize(new int[]{2, 0, 2, 4, 2, 5, 0, 1, 2, 3}));
    }
}
